package com.javafactroy.kunlong.domain.generalright.agg;

import com.javafactroy.kunlong.data.entity.DrUserEmpsApiEntity;
import com.javafactroy.kunlong.data.entity.DrUserGroupApiEntity;
import com.javafactroy.kunlong.data.entity.VUserGroupEmpsApiEntity;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Data
@Accessors(chain = true)
public class UserRightAgg {
    Long userId;
    Map<Long,Long> empIdMap;

    List<DptRightAgg> userDepts;

    List<DrUserGroupApiEntity> userGroups;
    List<VUserGroupEmpsApiEntity> userGroupEmps ;

    List<DrUserEmpsApiEntity> userEmps;

    public Boolean deptHasRight(Long deptId){
       List<DptRightAgg> depts= userDepts.stream().filter(i->i.getDptId().equals(deptId)).collect(Collectors.toList());
       return depts.size()>0;
    }
    public UserRightAgg mergeRightEmps() {
        empIdMap = new LinkedHashMap<>();
        for(DptRightAgg agg:userDepts) {
           agg.getEmpInfos().forEach(i->empIdMap.put(i.getEmpId(),i.getEmpId()));
        }
        userEmps.forEach(i->empIdMap.put(i.getEmpId(),i.getEmpId()));
        userGroupEmps.forEach(i->empIdMap.put(i.getEmpId(),i.getEmpId()));
        return this;
    }
}
